<template>
  <div class="card-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">车牌号码：</span>
      <el-input v-model="payData.carNumber" clearable placeholder="请输入内容" class="search-main" />
      <span class="search-label">缴纳状态：</span>
      <el-select v-model="payData.paymentStatus">
        <el-option
          v-for="item in paymentStatus"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        />
      </el-select>
      <el-button type="primary" class="search-btn" @click="serchList">查询</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table style="width: 100%" :data="tableData">
        <el-table-column type="index" label="序号" />
        <el-table-column label="车牌号码" prop="carNumber" />
        <el-table-column label="收费类型" prop="chargeType" :formatter="charge" />
        <el-table-column label="停车总时长" prop="parkingTime" />
        <el-table-column label="缴纳费用（元）" prop="actualCharge" />
        <el-table-column label="缴纳状态" prop="paymentStatus" :formatter="payment" />
        <el-table-column label="缴纳方式" prop="paymentMethod" :formatter="paymentMethod" />
        <el-table-column label="缴纳时间" prop="paymentTime" />
      </el-table>
    </div>
    <div class="page-container">
      <el-pagination
        layout="total, prev,sizes, pager, next"
        :page-size="payData.pageSize"
        :total="total"
        :page-sizes="[2, 5,10,20]"
        @current-change="pageChage"
        @size-change="handleSizeChange"
      />
    </div>
  </div>
</template>

<script>
import { getPayListAPI } from '@/api/pay'

export default {
  data() {
    return {
      payData: {
        page: 1,
        pageSize: 5,
        carNumber: '',
        chargeType: '',
        payStatus: '',
        parkingTime: '',
        actualCharge: '',
        paymentTime: '',
        paymentMethod: ''
      },
      tableData: [],
      total: 0,
      paymentStatus: [
        { id: 1, name: '已缴纳' },
        { id: 2, name: '未缴纳' }
      ]
    }
  },
  created() {
    this.getPayList()
  },
  methods: {
    async getPayList() {
      const res = await getPayListAPI(this.payData, this.dataParams)
      console.log(res)
      this.tableData = res.data.rows
      this.total = res.data.total
    },
    pageChage(val) {
      this.dataParams.page = val
      this.getCardList()
    },
    // 分页
    handleSizeChange(val) {
      this.payData.pageSize = val
      this.getPayList()
    },
    // 查询
    serchList() {
      this.payData.page = 1
      this.getPayList()
    },
    // 支付方式
    paymentMethod(row, column, cellValue, index) {
      console.log(row, column, cellValue, index)
      const statusMap = {
        Alipay: '支付宝支付',
        WeChat: '微信支付',
        Cash: '现金支付'
      }
      return statusMap[cellValue] || '---'
    },
    // 缴纳状态
    // eslint-disable-next-line vue/no-dupe-keys
    payment(row, column, cellValue, index) {
      console.log(row, column, cellValue, index)
      const statusMap = {
        1: '已缴纳',
        0: '未缴纳'
      }
      return statusMap[cellValue]
    },
    // 收费类型
    charge(row, column, cellValue, index) {
      console.log(row, column, cellValue, index)
      const statusMap = {
        card: '月卡',
        temp: '临时车'
      }
      return statusMap[cellValue]
    }
  }
}
</script>

<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 20px;
  .search-main {
    width: 220px;
    margin-right: 10px;
  }
  .search-btn{
    margin-left:20px;
  }
}
.create-container{
  margin: 10px 0px;
}
.page-container{
  padding:4px 0px;
  text-align: right;
}
.form-container{
  padding:0px 80px;
}
</style>
